-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store history in XDG data directory #253
Conversation
The new history file path is: echo "${XDG_DATA_HOME:-$HOME/.local/share}/swarm/history" The quick and easy way to migrate old history using data R = REPLEntry Bool String deriving Read
new_history = "<output of shell command above>"
readFile ".swarm_history" >>= pure . unlines . map (\(REPLEntry _ t) -> t) . read >>= writeFile new_history |
|
I am unhapy with the current
I could also do it as separate PR/Issue, but the first option is easy enough to do here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good to me. I agree REPLEntry Bool Bool
is not great (to be clear, it was my idea, I'm not blaming @Alexander-Block =). I don't have a strong opinion on how we should fix it, either of the things you proposed would be an improvement.
I also agree that Do you see concrete advantages of your second proposal compared to the first one, @xsebek? If not, I slightly prefer the first one for its simplicity. I guess it should not be too hard to refactor to the second proposal later if it turns out to be a better solution. However, this is also not a particularly strong opinion. |
@Alexander-Block I thought about it and I think wrapping We are indexing a lot into history and I somehow managed to change it and get it to work again (off by one errors are the worst) but it could definitely be refactored further. I originally hoped to have all functions taking EDIT: just to clarify, with sequence I abandoned stack-like indexing so the historically first entry has index 0 and instead of -1 I use |
Thank you for this thorough explanation. I agree with your arguments both for using However, I also agree that this implementation could benefit from further refactoring. I find it a bit worrying to expose details of the inner storage outside I would be happy to go through your code changes an do a more detailled review; I did not find the time to do that yesterday (which is why I write this vague comment), but I think that I will find time at some point today (from the perspective of the CEST time zone). Also I would be happy to propose unit tests as it will help me to better understand your code changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the approach of having a REPLHistory
type for a complete REPL history that is a wrapper around Seq
.
However, I think that the idea of a wrapper could and should be taken further than is the case in the current implementation. The three lenses replSeq
, replStart
and replIndex
completely reveal (and allow clients to manipulate) the inner structure of ReplHistory
. I propose not to export them, but rather add a few additional functions to Model.hs
to manipulate and access information from a REPLHistory
. As I said earlier this will make it easier to unit test the behaviour connected with REPLHistory
.
Apart from this I unfortunately found an error in drawREPL
that should be corrected before merging this pull request.
Thanks for your detailed review @Alexander-Block, I am working through it and fixing bugs! 🐛🔨 |
For fun I also added a debugging line to show the index: ┌──────────────── string ──┐
│ > (\x. "a") 1 │
│ 56 │
└──────────────────────────┘ It is triggered by this line in debugging = False -- Turn ON to get extra line with history index
inputLines = 1 + fromEnum debugging Could be useful for #134. 🙂 |
I'm pretty happy with the result and I even added some unit tests so hopefully it works now. 😄 Could you please check it out and see if I did not miss anything, @Alexander-Block and @byorgey? |
I noticed that the status of my review was still "requesting changes"; the reason for this status was the bug I noticed and which has since been fixed. There are still unresolved conversations, but these contain only comments which may or may not lead to changes in this PR and should probably not prevent a merge. |
I think it looks good too, though I seem to recall @xsebek wanting to add some tests first? Or am I getting it confused with something else? |
@xsebek has added unit tests (cf |
- use Seq as inner storage - skip same entries using predicate - store index of first input that is not saved
@byorgey You might be thinking about #270, where I would indeed like to write some tests first 🙂 @Alexander-Block sorry for the delay, I actually had the changes you proposed implemented for almost a week now, just did not get around to test and push them 😉 |
REPLEntry
REPLHistory
type and its pure functions